import { createBrowserRouter } from "react-router-dom";
import Root from "../pages/root/root.jsx";
import ErrorPage from "../err-page.jsx";
import Login from "../pages/login/index.jsx";
import { mainRoutes } from "@/router/main.jsx";
import RouterGuard from "./helper/RouterGuard";

export const routesConfig = [
  {
    path: "/",
    element: <Root />,
    errorElement: <ErrorPage />,
    children: [
      {
        errorElement: <ErrorPage />,
        children: mainRoutes,
      },
    ],
  },
  {
    path: "/login",
    element: <Login />,
  },
];

const WrapRoutes = routesConfig.map((item) => {
  return { ...item, element: <RouterGuard>{item.element}</RouterGuard> };
});
export const routes = createBrowserRouter(WrapRoutes, {
  future: {
    v7_normalizeFormMethod: true,
  },
});
